<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" class="demo-tabs" stretch v-model="loginMode">
      <el-tab-pane name="account">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon class="user"><User /></el-icon>
            <span>账户登录</span>
          </span>
        </template>
        <LoginAccount ref="accountRef"></LoginAccount>
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon class="phone"><Iphone /></el-icon>
            <span>手机登录</span>
          </span>
        </template>
        <LoginPhone ref="phoneRef"></LoginPhone>
      </el-tab-pane>
    </el-tabs>
    <el-button type="primary" class="login" @click="login">立即登录</el-button>
    <div class="keep-password">
      <el-checkbox v-model="keePassword">记住密码</el-checkbox>
      <el-link :underline="false">忘记密码</el-link>
    </div>
  </div>
</template>

<script setup lang="ts">
import { User, Iphone } from '@element-plus/icons-vue';
import LoginAccount from './login-account.vue';
import LoginPhone from './login-phone.vue';
import { ref } from 'vue';

const keePassword = ref(true);
const accountRef = ref<InstanceType<typeof LoginAccount>>();
const phoneRef = ref<InstanceType<typeof LoginPhone>>();
const loginMode = ref('account');
const login = () => {
  if (loginMode.value === 'account') {
    accountRef.value?.accountLogin(keePassword.value);
  } else {
    phoneRef.value?.phoneLogin();
  }
};
</script>

<style lang="less" scoped>
.login-panel {
  margin-bottom: 100px;
  .title {
    text-align: center;
  }
  .demo-tabs {
    width: 320px;
    .custom-tabs-label span {
      vertical-align: middle;
      margin-left: 4px;
    }
    .custom-tabs-label .el-icon {
      vertical-align: middle;
    }
  }
  .demo-tabs > .el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
  }
  .keep-password {
    display: flex;
    justify-content: space-between;
  }
  .login {
    width: 100%;
    margin-top: 10px;
  }
}
</style>
